/**
 * 
 *
 * 字符          数值
    I             1
    V             5
    X             10
    L             50
    C             100
    D             500
    M             1000 
 */

/**
 * @param {string} s
 * @return {number}
 */
var romanToInt = function(s) {
  let obj = {
    'I': 1,
    'V': 5,
    'X': 10,
    'L': 50,
    'C': 100,
    'D': 500,
    'M': 1000,
    'IV': 4,
    'IX': 9,
    'XL': 40,
    'XC': 90,
    'CD': 400,
    'CM': 900,
  }
  let arr = []
  let sum = 0
  let value = s.split('')

  for (let i = 0; i < value.length; i++) {
    if ((value[i] === 'I' && value[i + 1] && (value[i + 1] === 'V' ||  value[i + 1] === 'X')) || (value[i] === 'X' && value[i + 1] && (value[i + 1] === 'L' ||  value[i + 1] === 'C')) || (value[i] === 'C' && value[i + 1] && (value[i + 1] === 'D' ||  value[i + 1] === 'M'))) {
      arr.push(`${value[i]}${value[i+1]}`)
      i++
    } else {
      arr.push(value[i])
    }
    console.log('value::', arr)
  }

  for (const v of arr) {
    sum += obj[v]
  }
  return sum
};

console.log('[ romanToInt(MII) ] >', romanToInt('III'))